<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="80%" destroy-on-close @closed="$emit('closed')" align-center>
        <el-header>
            <div class="left-panel">
                <div class="right-panel-search">
                    <div class="search-input">skc</div>
                    <el-input v-model="search.skc" placeholder="请输入skc" clearable @change="handleKeyDown" />
                    <div class="search-input">色号</div>
                    <el-input v-model="search.color_number" placeholder="请输入色号" clearable @change="handleKeyDown" />
                    <div class="search-input">颜色</div>
                    <el-input v-model="search.colour" placeholder="请输入颜色" clearable @change="handleKeyDown" />
                    <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" @selection-change="selectionChange" stripe remoteSort remoteFilter border height='500'>
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column type="index" width="50"></el-table-column>
                <el-table-column label="物料类别" align="center" width="100">
                    <template #default="scope">
                        <div v-if="scope.row.material">{{scope.row.material.category_name}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="物料编码" prop="spec_code" align="center" width="210"></el-table-column>
                <el-table-column label="物料名称" align="center">
                    <template #default="scope">
                        <div v-if="scope.row.material">{{scope.row.material.material_name}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="色号" prop="color_number" align="center"></el-table-column>
                <el-table-column label="颜色" prop="colour" align="center"></el-table-column>
                <el-table-column label="单位" align="center">
                    <template #default="scope">
                        <div v-if="scope.row.material">{{scope.row.material.unit_name}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="供应商" align="center">
                    <template #default="scope">
                        <div v-if="scope.row.material">{{scope.row.material.referred_as}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="备注" prop="remark" align="center"></el-table-column>
            </scTable>
        </el-main>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" @click="back" :disabled="selection.length == 0">选择</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择物料',
			},
			visible: false,
			isSaveing: false,
            apiObj: this.$API.develop.edition.query,
            selection: [],
            wuIndex:"",
            search:{
                skc:"",
                colour:"",
                color_number:"",
            },
            tableData:[]
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        selectionChange(selection) {
			this.selection = selection;
		},
        back(){
            this.$emit('success', this.selection, this.wuIndex)
            this.visible = false;
        },
        async setData(data) {
			this.wuIndex = data.type
		},
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
	}
}
</script>

<style></style>
